package com.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.constant.MessageConstant;
import com.pojo.Setmeal;
import com.result.Result;
import com.service.SetmealService;
import com.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/setMealMobile")
public class SetMealMobileController {

    @Reference
    private SetmealService setmealService;

    @PostMapping("/findByIds")
    public Result findByIds(Integer id){
        try {
            Setmeal setmeal = setmealService.queryById(id);
            Map map=new HashMap();
            map.put("setmeal",setmeal);
            map.put("domain",QiNiuUtils.DOMAIN);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,map);
        }catch (Exception e){

        }
        return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
    }



    @PostMapping("/findById")
    public Result findById(Integer id){
        try {
            Setmeal setmeal = setmealService.queryDetailById(id);
            Map map=new HashMap();
            map.put("setmeal",setmeal);
            map.put("domain",QiNiuUtils.DOMAIN);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,map);
        }catch (Exception e){

        }
        return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
    }


    @RequestMapping("/getSetmeal")
    public Result getSetmeal(){
        try {
            List<Setmeal> list = setmealService.findAll();
            list.forEach(s->{
                s.setImg(QiNiuUtils.DOMAIN+s.getImg());
            });
            return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false,MessageConstant.QUERY_SETMEALLIST_FAIL);
    }

}
